home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Help with pointer alignment
- Date: Thu, 08 Feb 96 14:21:13 GMT
- Organization: none
- Message-ID: <823789273snz@genesis.demon.co.uk>
- References: <4fb0op$8l8@hermes.louisville.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4fb0op$8l8@hermes.louisville.edu>
- arwild01@homer.louisville.edu "Alan Wild" writes:
-
- >I am having a small problem with pointer alignment in a library I am
- >developing. lint reports:
- >
- >"queue.c", line 13: warning: possible pointer alignment problem, op CAST
- >
- >And the code is as follows:
- >
- >struct dataChain {
- > ORD64 dataf;
- > ORD64 be;
- > int cycle;
- >struct dataChain *next;
- >};
- >
- >typedef struct dataChain queueentry;
- >
- >void Append ( queueentry new, queue *Q ) {
- >
- > queueentry *temp = (queueentry *)malloc( sizeof( queueentry ) );
-
- Did you include stdlib.h? It is generally better not to cast the return
- value of malloc if you are using an ANSI compiler (which you probably are
- since you are used a function prototype). ANSI malloc should be declared in
- stdlib.h as returning void * and a reasonable compiler should not complain
- about converting void * to a pointer to object type. Non-ANSI header files
- might declare malloc as returning char *. In that case the cast is necessary
- and it is reasonable for a good compiler to warn about alignment problems.
- However in this case that warning can safely be ignored.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-